#include <iostream>
using namespace std;
const int N = 2510 , INF = 1e9;
int g[N][N];
int n , m , s , t;
void floyd()
{
    for(int k = 1 ; k <= n ; ++k)
        for(int i = 1 ; i <= n ; ++i)
            for(int j = 1 ; j <= n ; ++j)
                g[i][j] = min(g[i][j],g[i][k] + g[k][j]);
}
int main()
{
    scanf("%d%d%d%d",&n,&m,&s,&t);
    for(int i = 1 ; i <= n ; ++i)
        for(int j = 1 ; j <= n ; ++j)
            if(i == j) g[i][j] = 0;
            else g[i][j] = INF;
            
    while(m--)
    {
        int a , b , w;
        scanf("%d%d%d",&a,&b,&w);
        g[a][b] = min(g[a][b],w);
        g[b][a] = g[a][b];
    }
    floyd();
    printf("%d\n",g[s][t]);
    return 0;
}